package ws;

import java.util.ArrayList;
import java.util.Collection;

import org.orm.PersistentException;

import SOAPVO.EmpresaVO;
import SOAPVO.LibroVO;

import com.google.gson.Gson;

public class EmpresaSOA {
	private static final int ROW_COUNT = 100;

	public String findempresa(){
		String json = "";
		orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();
		Collection<EmpresaVO> empresa = new ArrayList<EmpresaVO>();
		try {
			orm.Empresa[] ormEmpresas = lDAOFactory.getEmpresaDAO().listEmpresaByQuery(null, null);
			int length = Math.min(ormEmpresas.length, ROW_COUNT);
			if(length != 0){
			for (int i = 0; i < length; i++) {
				empresa.add(new EmpresaVO(ormEmpresas[i]));
			}
			}
		} catch (PersistentException e) {
			// TODO Auto-generated catch block
			json = "ERROR";
		}
		json = new Gson().toJson(empresa);
		return json;

	}
	
	
	public String findlibro(int idEmpresa){
		String json = "";
		orm.DAOFactory lDAOFactory = orm.DAOFactory.getDAOFactory();
		Collection<LibroVO> libro = new ArrayList<LibroVO>();
		try {
			orm.Libro[] ormLibros = lDAOFactory.getLibroDAO().listLibroByQuery("empresaem.em_id = "+idEmpresa, null);
			int length = Math.min(ormLibros.length, ROW_COUNT);
			if (length !=0){
			for (int i = 0; i < length; i++) {
				libro.add(new LibroVO(ormLibros[i]));
			}
			}
		} catch (PersistentException e) {
			// TODO Auto-generated catch block
			json = "ERROR";
		}
		json = new Gson().toJson(libro);
		return json;

	}

}
